package day3.Exer;

import java.util.Scanner;

public class Customer {
    String[] name = new String[30];
    Scanner in = new Scanner(System.in);

    public void add(String custName) {
        for (int i = 0; i < name.length; i++) {
            if (name[i] == null) {
                name[i] = custName;
                return;
            }
        }
        System.out.println("客户信息已满!");
    }

    public void showcust() {
        for (int i = 0; i < name.length; i++) {
            if (name[i] == null) {
                break;
            }
            System.out.print(name[i] + "\t");
        }
        System.out.println();
    }
    public boolean searchName(int start, int end, String custName) {
        for (int i = start; start >= 0 && i <name.length && i <= end; i++) {
            if (name[i] == null)
                return false;

            if (name[i].equals(custName))
                return true;
        }
        return false;
    }

    public String find(int index) {
        if (index < 1 || index > name.length) {
            System.out.println("输入错误");
        }
        if (name[index - 1] == null) {
            System.out.println("你查找的位置没有登记顾客信息");
        } else {
            System.out.println("你查找的第" + index + "位顾客是" + name[index - 1]);
        }
        return name[index];
    }
    public void change(int index){
        while(true){
            if(index<1||index>name.length){
                System.out.println("输入的位置不在客户表中");
            }else if(name[index-1]==null){
                System.out.println("你查找的位置没有客户信息，无法修改");
            }else{
                ;
                for(int i=0;i<name.length;i++){
                    System.out.println("请输入您要更改的信息：");
                    String custName2=in.next();
                    if(name[i]==custName2){
                        System.out.println("您要修改的客户重名了，请重新输入");
                        continue;
                    }
                    name[index-1]=custName2;
                    break;
                }
                System.out.println("第"+index+"位客户修改为"+name[index-1]);
                return;
            }
        }
    }

}

